package com.ellricky.baselib.ui

import androidx.recyclerview.widget.LinearLayoutManager
import com.andr.common.ui.activity.BaseToolBarActivity
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.R
import com.ellricky.baselib.adapter.CluePoolAdapter
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.IdNameEntity
import com.ellricky.baselib.entity.new.CourseType
import com.ellricky.baselib.entity.new.TrackDetail
import com.ellricky.baselib.http.HttpUtils
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.baselib.util.NewECallback
import com.ellricky.baselib.util.NewEListCallback
import kotlinx.android.synthetic.main.base_activity_track.*
import java.util.HashMap

class TrackActivity : BaseToolBarActivity<Void, BasePresenter<Void>>() {

    private val id: String by lazy {
        intent.getStringExtra(BaseConstant.KEY_ID) ?: ""
    }

    private val adapter: CluePoolAdapter by lazy {
        CluePoolAdapter(this)
    }

    override fun getContentLayout(): Int {
        return R.layout.base_activity_track
    }

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = "跟踪记录"

        rvRecord.layoutManager = LinearLayoutManager(this)
        rvRecord.adapter = adapter

        fetchTrackRecord()
    }

    private fun fetchTrackRecord() {
        val url = EAppUtil.getApiHost()
        val paramMap: MutableMap<String, String> = HashMap()
        paramMap["action"] = getActions()
        paramMap["member_id"] = id
        paramMap["eid"] = LocalCacheUtil.getUid()

        HttpUtils.getInstance()
            .postFrom(url, paramMap, object : NewECallback<TrackDetail>(this) {
                override fun onSuccess(data: TrackDetail, msg: String) {
                    tv_time.text = data.input_time
                    item_person.value = data.input_name
                    item_from.value = data.from_name
                    item_remark.value = data.remark
                    if (data.return_list.isNotEmpty()) {
                        adapter.refresh(data.return_list)
                    }
                }
            })
    }

    private fun getActions(): String {
        return when (LocalCacheUtil.getCardType()) {
            BaseConstant.CARD_PRESIDENT -> "headMemberReturnList"
            else -> "memberReturnList"
        }
    }
}